package cn.iocoder.yudao.module.erp.dal.mysql.business.group.goodscategory;

import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.erp.controller.admin.business.group.goodscategory.vo.GoodsCategoryPageReqVO;
import cn.iocoder.yudao.module.erp.dal.dataobject.business.group.goodscategory.GoodsCategoryDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * 物品类目 Mapper
 *
 * @author yy
 */
@Mapper
public interface GoodsCategoryMapper extends BaseMapperX<GoodsCategoryDO> {

    default List<GoodsCategoryDO> selectPageList(GoodsCategoryPageReqVO reqVO) {
        return selectList( new LambdaQueryWrapperX<GoodsCategoryDO>()
                .likeIfPresent(GoodsCategoryDO::getName, reqVO.getName())
                .eqIfPresent(GoodsCategoryDO::getParentId,reqVO.getParentId())
                .orderByAsc(GoodsCategoryDO::getId));
    }
    default List<GoodsCategoryDO> selectList(){
        return selectList(new LambdaQueryWrapperX<GoodsCategoryDO>()
                .orderByAsc(GoodsCategoryDO::getId));
    }

    default Long selectCountByParentId(Long parentId){
        return selectCount(GoodsCategoryDO::getParentId, parentId);
    }

    default GoodsCategoryDO selectByParentAndName(Long parentId, String name){
        return selectOne(GoodsCategoryDO::getParentId,parentId, GoodsCategoryDO::getName,name);
    }
}